<?php
namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller {
	
	/**
	 * 登录首页
	 */
	public function index() {
		$userAuth = session('userAuth');
		if ( !$userAuth ) {
			$this->display( "login" );
		} else {
			$this->redirect( 'Index/index' );
		}
	}
	
	/**
	 * 登录
	 */
	public function login() {
		if ( IS_POST ) {
			$user = D( "User" );
			$result = $user->login( I( 'post.username' ), I( 'post.password' ), I( 'post.verify' ) );

			if ( is_numeric( $result ) ) {
				$this->redirect('Index/index');
			} else {
				$this->error( $result );
			}
		} else {
			$this->error( "非法操作!" );
		}
	}
	
	/**
	 * 退出登录
	 */
	public function logout() {
		session( 'userAuth', null );
		$this->redirect('Login/index');
	}
	
	/**
	 * 验证码
	 */
	public function verify() {
		$verify = new \Think\Verify( array( "length"=>4 ) );
		$verify->entry( 1 );
	}
}